package com.electron.server.controller;

import com.electron.server.dto.IntentDataDTO;
import lombok.extern.log4j.Log4j2;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
@Log4j2
public class TestWebSocketController {
    @MessageMapping("/test")
    public String test(String data) {
        return "测试成功";
    }

    /**
     * @param:
     * @return
     * @description 方法描述 根据设置此处应该是 app/hello
     * /topic/getResponse 为订阅
     * @author zhangqiang
     * @date 2019年06月06日 17:03
     */
    @MessageMapping("/hello")
//    @SendTo("/topic/getResponse")
    @SendToUser("/topic/receive")
    public String sub(@RequestBody IntentDataDTO data, StompHeaderAccessor accessor) throws InterruptedException {
//        log.error(data.toJson());
        log.error(data.getS1());
        return "感谢您订阅了我";
    }

    @MessageMapping("/welcome")
    @SendToUser("/welcome")
    public String say() throws Exception {
        return "成功";
    }

    @MessageMapping("/hellose")
    @SendToUser("/send")
    public String userGetMessage(@RequestBody IntentDataDTO data, Principal principal) {
        log.error(data.getS1());
        return "message";

    }

}
